package com.cyzy.controller;

import com.cyzy.dto.Result;
import com.cyzy.pojo.CourseCategory;
import com.cyzy.service.CourseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/courseCategory")
public class CourseCategoryController {

    @Autowired
    private CourseCategoryService categoryService;

    @GetMapping("/page")
    public Result getCategoryPage(
            @RequestParam(defaultValue = "1") Long currentPage,
            @RequestParam(defaultValue = "10") Long pageSize,
            @RequestParam(required = false) String categoryName,
            @RequestParam(required = false) Long campusId,
            @RequestParam(required = false) String isVisible,
            @RequestParam(required = false) String campusName) {

        CourseCategory category = new CourseCategory();
        category.setCurrentPage(currentPage);
        category.setPageSize(pageSize);
        category.setCategoryName(categoryName);
        category.setCampusId(campusId);
        category.setIsVisible(isVisible);
        category.setCampusName(campusName);

        return categoryService.getCategoryPage(category);
    }

    @PostMapping("/add")
    public Result addCategory(@RequestBody CourseCategory category) {
        return categoryService.addCategory(category);
    }

    @PostMapping("/update")
    public Result updateCategory(@RequestBody CourseCategory category) {
        return categoryService.updateCategory(category);
    }

    @PostMapping("/delete/{categoryId}")
    public Result deleteCategory(@PathVariable Long categoryId) {
        return categoryService.deleteCategory(categoryId);
    }

    @PostMapping("/status/{categoryId}")
    public Result changeCategoryStatus(
            @PathVariable Long categoryId,
            @RequestParam String isVisible) {
        return categoryService.changeCategoryStatus(categoryId, isVisible);
    }
}